home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / vocpak20.zip / COMPR.C next >
C/C++ Source or Header  |  1993-09-01  |  2KB  |  85 lines

  1. /*
  2.  * Vocpack 2.0 Library  -  (C) 1993 Nicola Ferioli
  3.  *
  4.  * This program shows how to compress a file using Vocpack library functions.
  5.  * It works on 8-bit unsigned mono samples, but it can be easily modified.
  6.  * Link this program with one of the libraries VP_?.LIB, depending on the
  7.  * memory model used.
  8.  * To improve performance you can add disk buffering ( setvbuf() ).
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include "vocpack.h"
  13.  
  14.  
  15. FILE *In,    /* source file to be compressed */
  16.      *Out;    /* destination file */
  17.  
  18.  
  19. /*
  20.  * I/O functions needed by Vocpack Library
  21.  */
  22.  
  23. void VP_Output (int c)            /* output c to destination file */
  24. {
  25.  putc(c, Out);
  26. }
  27.  
  28. void VP_OutputSeek (long Offset)    /* go to position Offset */
  29. {
  30.  fseek(Out, Offset, SEEK_SET);
  31. }
  32.  
  33. /* VP_Input and VP_InputRewind are not needed when packing */
  34. int  VP_Input (void) { return 0; }
  35. void VP_InputRewind (void) { return; }
  36.  
  37.  
  38.  
  39. /*
  40.  * MAIN
  41.  */
  42.  
  43. void main (int argc, char *argv[])
  44. {
  45.  int c;            /* character read from input file */
  46.  VP_Info Info;        /* type of data to compress */
  47.  
  48.  
  49.  /* check command-line parameters */
  50.  if (argc != 3) {
  51.     puts("\nUsage:  COMPR <source> <dest>");
  52.     return; }
  53.  
  54.  /* open source and destination files */
  55.  if ( (In = fopen(argv[1], "rb")) == NULL ) {
  56.     printf("\nFile not found %s\n", argv[1]);
  57.     return; }
  58.  
  59.  if ( (Out = fopen(argv[2], "wb")) == NULL ) {
  60.     printf("\nCan't create %s\n", argv[2]);
  61.     return; }
  62.  
  63.  /* Set the type of data to compress: 8-bit unsigned mono, no alignment. */
  64.  /* The file name is the <source> field of the command line. */
  65.  /* Info.UnpackedLen is unused */
  66.  Info.IsSigned = 0;
  67.  Info.IsStereo = 0;
  68.  Info.Is16Bit = 0;
  69.  Info.Align = 0;
  70.  Info.Name = argv[1];
  71.  
  72.  /* init compression routine */
  73.  VP_InitPack(&Info);
  74.  
  75.  /* compression loop: get a character and compress it */
  76.  while ( (c = getc(In)) != EOF )
  77.     VP_Pack(c);
  78.  
  79.  /* end of compression */
  80.  VP_EndPack();
  81.  
  82.  /* close files */
  83.  fclose(In);
  84.  fclose(Out);
  85. }